import { create } from 'zustand';
import { persist } from 'zustand/middleware';
import { KeyStore } from './type'

const keyStore = create<KeyStore>()(
    persist(
        (set) => ({
            user: '',
            // key: 'app-5ccHqEWlqZ0AbPIxyYDSjYMd',
            key: 'app-J4ozWYK7UJv1FAOIJiniP30X',
            // 文本生成
            dockey: 'app-5ccHqEWlqZ0AbPIxyYDSjYMd',
            conversation_id: '',
            isdoc: false,
            setKey: (key) => {
                set({ key });
            },
            setconversation_id: (conversation_id) => {
                set({ conversation_id });
            },
            setUser: (user) => {
                set({ user })
            },
            setisdoc: (isdoc) => {
                set({ isdoc })
            }
        }),
        {
            name: 'key-store', // 持久化存储的名称
            partialize: (state) => ({
                user: state.user,
                isdoc: state.isdoc,
                conversation_id: state.conversation_id,
            }),
        }
    )
);

export default keyStore;